package org.huolala.utils;

import java.util.List;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.annotation.WebListener;

import org.huolala.dao.CarTypeDao;
import org.huolala.pojo.CarType;
import org.springframework.context.ApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

@WebListener
public class InitDataListener implements ServletContextListener {

	@Override
	public void contextDestroyed(ServletContextEvent arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void contextInitialized(ServletContextEvent arg0) {
		ApplicationContext context = WebApplicationContextUtils.getWebApplicationContext(arg0.getServletContext());
		CarTypeDao carTypeDao = (CarTypeDao) context.getBean("carTypeDao");
		List<CarType> list = carTypeDao.getAll();
		arg0.getServletContext().setAttribute("carTypes", list);
		

	}

}
